﻿using BaseUI;
using BLL;
using System;
using System.Data;
using System.Web;
using System.Web.UI.WebControls;

namespace Thksoft
{
    public partial class Right : BasePage
    {
        private Qs_BusinessBLL qbb = new Qs_BusinessBLL();
        private Lc_TransactionBLL ltb = new Lc_TransactionBLL();
        private Sys_DepartmentBLL sdb = new Sys_DepartmentBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            //if (Session["Pro_ID"] != null)
            //{
            //    if (Session["Pro_ID"].ToString() == "1")
            //    {
            //        Response.Redirect("/BusinessExpansion/Templete/JX_PROCEDUREDETAILLIST.aspx");
            //        Session["Pro_ID"] = "0";
            //    }
            //    else if (Session["Pro_ID"].ToString() == "2")
            //    {
            //        Response.Redirect("/BusinessExpansion/Templete/JX_ANNUALDETAILLIST.aspx");
            //        Session["Pro_ID"] = "0";
            //    }
            //    else if (Session["Pro_ID"].ToString() == "3")
            //    {
            //        Response.Redirect("/JXKH/JX_GCKHREPORTHZ.aspx");
            //        Session["Pro_ID"] = "0";
            //    }
            //    else if (Session["Pro_ID"].ToString() == "4")
            //    {
            //        Response.Redirect("/JXKH/JX_YKHREPORTHZ.aspx");
            //        Session["Pro_ID"] = "0";
            //    }
            //}

            if (!IsPostBack)
            {
                Bind();//首次加载数据
                BindData(true);
            }

            if (Request.Cookies["tag"] == null)
            {
                HttpCookie cok = new HttpCookie("tag", "");
                cok.Path = "/";
                Response.AppendCookie(cok);
            }
            else
            {
                Request.Cookies["tag"].Value = "";
                Request.Cookies["tag"].Path = "/";
                Response.AppendCookie(Request.Cookies["tag"]);
            }

            if (Request.Cookies["frh"] == null)
            {
                HttpCookie cok = new HttpCookie("frh", "no");
                cok.Path = "/";
                Response.AppendCookie(cok);
            }
            else
            {
                Request.Cookies["frh"].Value = "no";
                Request.Cookies["frh"].Path = "/";
                Response.AppendCookie(Request.Cookies["frh"]);
            }
        }

        private string GetDate(string date)
        {
            string t = "";
            try
            {
                DateTime time = Convert.ToDateTime(date.ToString());

                decimal mouth = decimal.Parse(time.Month.ToString());
                decimal day = decimal.Parse(time.Day.ToString());
                if (mouth < 10 && day >= 10)
                {
                    t = "[ 0" + mouth + "-" + day + " ]";
                }
                else if (day < 10 && mouth >= 10)
                {
                    t = "[ " + mouth + "-0" + day + " ]";
                }
                else if (day < 10 && mouth < 10)
                {
                    t = "[ 0" + mouth + "-0" + day + " ]";
                }
                else
                {
                    t = "[ " + mouth + "-" + day + " ]";
                }
            }
            catch
            {
                DateTime time = DateTime.Now;
                decimal mouth = decimal.Parse(time.Month.ToString());
                decimal day = decimal.Parse(time.Day.ToString());
                if (mouth < 10 && day >= 10)
                {
                    t = "[ 0" + mouth + "-" + day + " ]";
                }
                else if (day < 10 && mouth >= 10)
                {
                    t = "[ " + mouth + "-0" + day + " ]";
                }
                else if (day < 10 && mouth < 10)
                {
                    t = "[ 0" + mouth + "-0" + day + " ]";
                }
                else
                {
                    t = "[ " + mouth + "-" + day + " ]";
                }
            }
            return t;
        }

        private void Bind()
        {
            string InerHtmls = "<div ><ul>";
            //查询待办信息
            DataTable temp = ltb.GetAgentDataAll(lognUser);//ltb.GetAgentData(lognUser.USER_ID.ToString(), lognUser);
            if (temp != null)
            {
                Label1.Text = temp.Rows.Count.ToString();
            }

            //DataTable dt = qbb.GetMessage(lognUser.USER_DEPARTMENT.ToString());

            #region 业务

            int dbnum = 0;
            if (temp != null && temp.Rows.Count > 0)
            {
                for (int i = 0; i < temp.Rows.Count; i++)
                {
                    dbnum++;
                    string stateDue = "";
                    if (dbnum <= 9)
                    {
                        string str = "【" + temp.Rows[i]["process"].ToString() + "】'" + temp.Rows[i]["business"].ToString() + "' " + temp.Rows[i]["nodename"].ToString() + "待处理" + stateDue;

                        str = SubStr(str);
                        InerHtmls += "<li id='" + temp.Rows[i]["tranid"] + "'><span>" + GetDate(temp.Rows[i]["d_transaction_time_begin"].ToString()).ToString() + "</span><a href='BusinessExpansion/Business/BussTran.aspx?trancId=" + temp.Rows[i]["tranid"].ToString() + "&BusinessId=" + temp.Rows[i]["bid"].ToString() + "'>" + str + "";
                        //<%--<img src='../Images/delete.gif' runat='server' onclick='deleteid(" + temp.Rows[i]["tranid"] + ");' title='暂不显示' width='10px' height='7px'/>--%>

                        DateTime time = DateTime.Parse(temp.Rows[i]["d_transaction_time_begin"].ToString()).AddDays(10);//10天以内的有图标
                        DateTime now = DateTime.Now;
                        if (time >= now)
                        {
                            InerHtmls += "<img src='../Images/main_right/new.gif'/> ";
                        }
                        InerHtmls += "</a></li>";
                    }
                }
            }
            /*
            if (dt.Rows.Count > 0)
            {
                string str = "【考核消息】'" + dt.Rows[0]["C_TITLE"].ToString().Trim() + "' 待查看";
                Sys_Department dModel = sdb.GetInfoById(lognUser.USER_DEPARTMENT.ToString());
                if (dModel != null)
                {
                    str += "<" + dModel.DEPTNAME + ">";
                }
                str = SubStr(str);

                InerHtmls += "<li><span>" + GetDate(dt.Rows[0]["D_OPDATE"].ToString()).ToString() + "</span><a href='BusinessExpansion/Business/ShowMessage.aspx?MESSAGE_ID=" + dt.Rows[0]["MESSAGE_ID"].ToString() + "'>" + str;

                DateTime time = DateTime.Parse(dt.Rows[0]["D_OPDATE"].ToString()).AddDays(10);//10天以内的有图标
                DateTime now = DateTime.Now;
                if (time >= now)
                {
                    InerHtmls += "<img src='../Images/main_right/new.gif'/> ";
                }
                InerHtmls += "</a></li>";
            }
            */

            #endregion 业务

            InerHtmls += "</ul></div> ";
            div1.InnerHtml = InerHtmls;
        }

        private void BindData(bool isFirst)
        {
            string Where = "";
            try
            {
                Where = ViewState["Where"].ToString();
            }
            catch
            {
                Where = "";
            }

            int rowcount = 0;
            if (isFirst)
            {
                PageIng.CurrentPage = 1;
            }
            PageIng.RowsPerPage = 5;//每页5行数据

            rowcount = ltb.GetCountYBSY(lognUser.USER_ID.ToString(), "");

            Label2.Text = rowcount.ToString();

            DataTable dt = ltb.GetListByPageYBSY(lognUser.USER_ID.ToString(), "", " B.N_BUSINESS_ID DESC  ", PageIng.CurrentPage, PageIng.RowsPerPage);

            PageIng.Visible = true;
            PageIng.RowsCount = rowcount;
            PageIng.DataSource = dt;
            PageIng.GridViewSource = grvShow;
            PageIng.Bind();
        }

        private string SubStr(string str)
        {
            if (str.Length > 50)
            {
                str = str.Substring(0, 50) + "...";
            }
            return str;
        }

        protected void grvData_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].HorizontalAlign = HorizontalAlign.Center;
                if (e.Row.RowIndex >= 0)
                {
                    e.Row.Attributes.Add("onmouseover", "c=style.backgroundColor;style.backgroundColor='#d5e7ff'");
                    e.Row.Attributes.Add("onmouseout", "style.backgroundColor=c");
                }
            }
        }

        protected void PageIng_DataBinding(object sender, EventArgs e)
        {
            BindData(false);
        }
    }
}